home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Graphics⁄Sound / Fudd Source / Fudd ƒ / MSG Shell ƒ / msg help.c < prev    next >
Text File  |  1994-02-07  |  4KB  |  204 lines

  1. /**********************************************************************\
  2.  
  3. File:        msg help.c
  4.  
  5. Purpose:    This module handles displaying the different help windows.
  6.  
  7.  
  8. Fudd -=- convert text to Elmer Fudd talk
  9. Copyright ©1994, Mark Pilgrim
  10.  
  11. This program is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; either version 2 of the License, or
  14. (at your option) any later version.
  15.  
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. GNU General Public License for more details.
  20.  
  21. You should have received a copy of the GNU General Public License
  22. along with this program in a file named "GNU General Public License".
  23. If not, write to the Free Software Foundation, 675 Mass Ave,
  24. Cambridge, MA 02139, USA.
  25.  
  26. \**********************************************************************/
  27.  
  28. #include "msg help.h"
  29. #include "msg graphics.h"
  30. #include "msg menus.h"
  31. #include "program globals.h"
  32.  
  33. int                gWhichHelp;
  34. Handle            gHelpIcon[4];
  35.  
  36. void InitHelp(void)
  37. {
  38.     int                i;
  39.     
  40.     for (i=0; i<4; i++)
  41.         gHelpIcon[i]=GetIcon(128+i);
  42. }
  43.  
  44. void DrawTheHelp(Boolean isColor)
  45. {
  46.     GrafPtr            curPort;
  47.     int                row;
  48.     Handle            textHandle;
  49.     Str255            theLine;
  50.     unsigned long    pos;
  51.     unsigned long    theSize;
  52.     unsigned char    theChar;
  53.     Rect            iconRect;
  54.     
  55.     GetPort(&curPort);
  56.     EraseRect(&(curPort->portRect));
  57.  
  58.     TextFont(geneva);
  59.     TextSize(9);
  60.     row=63;
  61.     textHandle=GetResource('TEXT', 399+gWhichHelp);
  62.     if (textHandle==0L)
  63.         return;
  64.     if (*textHandle==0L)
  65.         LoadResource(textHandle);
  66.     if (*textHandle==0L)
  67.         return;
  68.     pos=0L;
  69.     theSize=SizeResource(textHandle);
  70.     do
  71.     {
  72.         theLine[0]=0x00;
  73.         while ((pos<theSize) && ((theChar=*((unsigned char*)(((long)(*textHandle))+(pos++))))!=0x0d))
  74.         {
  75.             if (theChar=='^')
  76.                 AddNameToString(theLine, APPLICATION_NAME);
  77.             else
  78.             theLine[++theLine[0]]=theChar;
  79.         }
  80.         MoveTo(8, row);
  81.         DrawString(theLine);
  82.         row+=12;
  83.     }
  84.     while (pos<theSize);
  85.     ReleaseResource(textHandle);
  86.     
  87.     MoveTo(0, 46);
  88.     Line(300, 0);
  89.     
  90.     SetRect(&iconRect, 20, 7, 52, 39);
  91.     PlotIcon(&iconRect, gHelpIcon[0]);
  92.     OffsetRect(&iconRect, 228, 0);
  93.     PlotIcon(&iconRect, gHelpIcon[1]);
  94.     
  95.     GetItem(gHelpMenu, gWhichHelp, theLine);
  96.     TextFace(bold);
  97.     MoveTo(150-StringWidth(theLine)/2, 26);
  98.     DrawString(theLine);
  99.     TextFace(0);
  100. }
  101.  
  102. void AddNameToString(Str255 theLine, Str255 theStringToAdd)
  103. {
  104.     int            i;
  105.     
  106.     for (i=1; i<=theStringToAdd[0]; i++)
  107.         theLine[++theLine[0]]=theStringToAdd[i];
  108. }
  109.  
  110. void HelpEvent(void)
  111. {
  112.     Point        mouseLoc;
  113.     Rect        iconRect;
  114.     Boolean        isHilited;
  115.     
  116.     GetMouse(&mouseLoc);
  117.     SetRect(&iconRect, 20, 7, 52, 39);
  118.     if (PtInRect(mouseLoc, &iconRect))
  119.     {
  120.         isHilited=FALSE;
  121.         while (StillDown())
  122.         {
  123.             GetMouse(&mouseLoc);
  124.             if (PtInRect(mouseLoc, &iconRect))
  125.             {
  126.                 if (!isHilited)
  127.                     PlotIcon(&iconRect, gHelpIcon[2]);
  128.                 isHilited=TRUE;
  129.             }
  130.             else
  131.             {
  132.                 if (isHilited)
  133.                     PlotIcon(&iconRect, gHelpIcon[0]);
  134.                 isHilited=FALSE;
  135.             }
  136.         }
  137.         if (isHilited)
  138.         {
  139.             gWhichHelp--;
  140.             if (gWhichHelp==0)
  141.                 gWhichHelp=gNumHelp;
  142.             UpdateHelpWindow();
  143.         }
  144.     }
  145.     else
  146.     {
  147.         OffsetRect(&iconRect, 228, 0);
  148.         if (PtInRect(mouseLoc, &iconRect))
  149.         {
  150.             isHilited=FALSE;
  151.             while (StillDown())
  152.             {
  153.                 GetMouse(&mouseLoc);
  154.                 if (PtInRect(mouseLoc, &iconRect))
  155.                 {
  156.                     if (!isHilited)
  157.                         PlotIcon(&iconRect, gHelpIcon[3]);
  158.                     isHilited=TRUE;
  159.                 }
  160.                 else
  161.                 {
  162.                     if (isHilited)
  163.                         PlotIcon(&iconRect, gHelpIcon[1]);
  164.                     isHilited=FALSE;
  165.                 }
  166.             }
  167.             if (isHilited)
  168.             {
  169.                 gWhichHelp++;
  170.                 if (gWhichHelp>gNumHelp)
  171.                     gWhichHelp=1;
  172.                 UpdateHelpWindow();
  173.             }
  174.         }
  175.     }
  176. }
  177.  
  178. void HelpKeyEvent(char keyPressed)
  179. {
  180.     switch (keyPressed)
  181.     {
  182.         case 0x1c:
  183.             gWhichHelp--;
  184.             if (gWhichHelp==0)
  185.                 gWhichHelp=gNumHelp;
  186.             UpdateHelpWindow();
  187.             break;
  188.         case 0x1d:
  189.             gWhichHelp++;
  190.             if (gWhichHelp>gNumHelp)
  191.                 gWhichHelp=1;
  192.             UpdateHelpWindow();
  193.             break;
  194.     }
  195. }
  196.  
  197. void ShutDownHelp(void)
  198. {
  199.     int            i;
  200.     
  201. //    for (i=0; i<4; i++)
  202. //        ReleaseResource(gHelpIcon[i]);
  203. }
  204.